home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / gem / l_1199 / 1000 next >
Text File  |  1994-08-27  |  4KB  |  126 lines

  1. Subject: Re: GEM apps, in general 
  2. Date: Mon, 25 Jul 1994 10:26:00 +1000
  3. From: Warwick Allison <warwick@cs.uq.oz.au>
  4. Precedence: bulk
  5.  
  6. Michel Forget wrote:
  7. >Do you have any that shows how
  8. >to scroll a window using the rectangle list and raster copies?  That
  9. >would be a pretty complex operation, I would think.
  10.  
  11. This code is from GEM++.  Obviously, it's C++, but the guts of it should
  12. be useful to you.  I've added comments on the external function calls.
  13.  
  14.  
  15. void GEMscrollableobject::Scroll(int pixels_right, int pixels_down)
  16. {
  17.   if (pixels_down || pixels_right) {
  18.     int X,Y;
  19.     GetAbsoluteXY(X,Y); // ie. use objc_offset to cal object position.
  20.  
  21.     // Walk the rectangle list (form.FirstClip/form.NextClip).
  22.     for (GRect* clip=form.FirstClip(myindex); clip; clip=form.NextClip(clip)) {
  23.       int pxy[8];
  24.  
  25.       // Anything to scroll?
  26.       if (abs(pixels_right)<clip->g_w
  27.        && abs(pixels_down)<clip->g_h) {
  28.         if (pixels_right>0) {
  29.           pxy[0]=clip->g_x+pixels_right;
  30.           pxy[2]=clip->g_x+clip->g_w-1;
  31.           pxy[4]=clip->g_x;
  32.           pxy[6]=clip->g_x+clip->g_w-pixels_right-1;
  33.         } else {
  34.           pxy[0]=clip->g_x;
  35.           pxy[2]=clip->g_x+clip->g_w+pixels_right-1;
  36.           pxy[4]=clip->g_x-pixels_right;
  37.           pxy[6]=clip->g_x+clip->g_w-1;
  38.         }
  39.  
  40.         if (pixels_down>0) {
  41.           pxy[1]=clip->g_y+pixels_down;
  42.           pxy[3]=clip->g_y+clip->g_h-1;
  43.           pxy[5]=clip->g_y;
  44.           pxy[7]=clip->g_y+clip->g_h-pixels_down-1;
  45.         } else {
  46.           pxy[1]=clip->g_y;
  47.           pxy[3]=clip->g_y+clip->g_h+pixels_down-1;
  48.           pxy[5]=clip->g_y-pixels_down;
  49.           pxy[7]=clip->g_y+clip->g_h-1;
  50.         }
  51.  
  52.         ro_cpyfm(VDI::SRC,pxy); // Screen-to-screen raster copy (vro_cpyfm)
  53.  
  54.         if (pixels_right>0) {
  55.           // This is just constructing a rectangle with the given dimensions.
  56.           GRect redraw_side(clip->g_x+clip->g_w-pixels_right,clip->g_y,
  57.             pixels_right,clip->g_h);
  58.  
  59.           RedrawClipped(X,Y,redraw_side); // RedrawClipped is below.
  60.         } else if (pixels_right) {
  61.           GRect redraw_side(clip->g_x,clip->g_y,-pixels_right,clip->g_h);
  62.           RedrawClipped(X,Y,redraw_side);
  63.         }
  64.  
  65.         if (pixels_down>0) {
  66.           if (pixels_right>0) {
  67.             GRect redraw_side(clip->g_x,clip->g_y+clip->g_h-pixels_down,
  68.               clip->g_w-pixels_right,pixels_down);
  69.             RedrawClipped(X,Y,redraw_side);
  70.           } else {
  71.             GRect redraw_side(clip->g_x-pixels_right,clip->g_y+clip->g_h-pixels_down,
  72.               clip->g_w+pixels_right,pixels_down);
  73.             RedrawClipped(X,Y,redraw_side);
  74.           }
  75.         } else if (pixels_down) {
  76.           if (pixels_right>0) {
  77.             GRect redraw_side(clip->g_x,clip->g_y,clip->g_w-pixels_right,-pixels_down);
  78.             RedrawClipped(X,Y,redraw_side);
  79.           } else {
  80.             GRect redraw_side(clip->g_x-pixels_right,clip->g_y,clip->g_w+pixels_right,-pixels_down);
  81.             RedrawClipped(X,Y,redraw_side);
  82.           }
  83.         }
  84.       } else {
  85.         RedrawClipped(X,Y,*clip);
  86.       }
  87.     }
  88.   }
  89. }
  90.  
  91. // This is the USEROBJ function (just here to show what RedrawClipped is)
  92. void GEMscrollableobject::Draw(const PARMBLK* p)
  93. {
  94.   GRect drawclip(p->pb_xc,p->pb_yc,p->pb_wc,p->pb_hc);
  95.   GRect objclip(p->pb_x,p->pb_y,GEMuserobject::Width(),GEMuserobject::Height());
  96.   drawclip.Clip(objclip);
  97.  
  98.   RedrawClipped(p->pb_x,p->pb_y,drawclip);
  99. }
  100.  
  101.  
  102. void GEMcanvas::RedrawClipped(int ox, int oy, const GRect& oarea)
  103. {
  104.     // White-out the whole area first (some applications don't need this)
  105.     r_recfl(oarea.g_x,oarea.g_y,oarea.g_x+oarea.g_w-1,oarea.g_y+oarea.g_h-1);
  106.  
  107.     // Set VDI clip area
  108.     clip(oarea.g_x,oarea.g_y,oarea.g_x+oarea.g_w-1,oarea.g_y+oarea.g_h-1);
  109.  
  110.     // And just draw whatever is in the window
  111.     GRect area(oarea.g_x-x,oarea.g_y-y,oarea.g_w,oarea.g_h);
  112.     DrawAt(ox-x,oy-y,area);
  113.  
  114.     // Turn of VDI clip
  115.     clip_off();
  116. }
  117.  
  118.  
  119.  
  120.  
  121. Hope that's useful to you.
  122.  
  123.  
  124. --
  125. Warwick
  126.